/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nol_app;

/**
 *
 * @author Sirius
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MysqlConnection {

	// Connection configuration
	private static String server = "vergil.u.washington.edu";
	private static String port = "60001";
	private static String database = "farlow_bryan_final";
	private static String username = "final_user";
	private static String password = "d9sd54afkl";

	private static boolean auto_commit = false;

	protected Connection conn;

	/**
	 * Connection constructor makes a connection to the MySQL database specified
	 * in the configuration variables declared above. Sets the conn member
	 * variable to a valid MySQL connection. Sets the auto commit of this
	 * connection using the configuration variable above.
	 */
	public MysqlConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			String connection_string = "jdbc:mysql://" + server + ":" + port
					+ "/" + database + "?" + "user=" + username + "&password="
					+ password;
			this.conn = DriverManager.getConnection(connection_string);
			this.conn.setAutoCommit(auto_commit);
		} catch (SQLException ex) {
			handleException(ex);
		}
	}

	protected static void handleException(SQLException ex) {
		// display any errors
		System.out.println("SQLException: " + ex.getMessage());
		System.out.println("SQLState: " + ex.getSQLState());
		System.out.println("VendorError: " + ex.getErrorCode());
	}
}
